package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;



import com.kaishengit.entity.User;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class UserDao {
	private DBHelp<User> db=new DBHelp<User>();
	public User findByUserNameAndPassword(User user){
		final String sql="select id,name,password from t_user where name=? and password=?";
		return db.executeQueryForObject(sql,new UserRowMapper(),user.getName(),user.getPassword());
	}
	
	public List<User> findAll(){
		final String sql="select id,name,password from t_user";
		return db.executeQueryForList(sql, new UserRowMapper());
	}

	private class UserRowMapper implements RowMapper<User> {

		public User mapRow(ResultSet rs) throws SQLException {
			User user=new User();
			user.setId(rs.getString("id"));
			user.setPassword(rs.getString("password"));
			user.setName(rs.getString("name"));
			return user;
			
		}
	
	}
}
